
import java.util.Scanner;

public class testmain {

	private static Scanner in; 
	
	public static void main(String[] args) {

		VerifyUser verifyUser = new VerifyUser();
		
		LoginController login = new LoginController(verifyUser);
		AccountController account = new AccountController();
		
		
		
		String userPrompt = "";
		int userLevel = 0;
		String userName = "";
		String password = "";
		boolean shouldContinue = true;
		in = new Scanner(System.in);

		while (shouldContinue) {
			//should keep user stuck in loop if unverified
			while (userLevel == 0) {
				// input for username
				System.out.println();
				System.out.print("Login:");
				userName = in.nextLine();

				// input for password
				System.out.println();
				System.out.print("Password:");
				password = in.nextLine();

				//pass login request to login controller
				userLevel = login.login(userName, password);
				
				if (userLevel != 0) {
					userPrompt = userName + ">";
					showOptions(userLevel);
				}
				else{
					System.out.println("Not a valid user");
				}
			}
			
			//loops if a valid user if found
			while (userLevel != 0) {
				//input put command
				System.out.println();
				System.out.print(userPrompt);
				String command = in.nextLine();
				
				//passes input commands off to whatever controller will process it
				
				//logoff command
				if(command.equalsIgnoreCase("logout")){
					userLevel = 0;
					userName = "";
					login.logoff();
					userPrompt = "";
				}
				
				//processing for add user command
				if(command.equalsIgnoreCase("adduser")){
					//retrieve data to input
					String newName = getInput("Enter Name");
					String newPassword = getInput("Enter Password");
					int newLevel = Integer.parseInt(getInput("Enter Level"));
					
					//only allow admins to create any user or teachers to create students
					if(userLevel == 1 || (userLevel == 2 && newLevel == 3)){
						
						account.createAccount(newName, newPassword, newLevel);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
					System.out.println("Successfully created Account.");
					
				}
		
				//processing for edit user
				if(command.equalsIgnoreCase("edituser")){
					String newName = getInput("Enter Name");
					int newLevel = Integer.parseInt(getInput("Enter Level"));
					
					//only allow admins to edit user
					if(userLevel == 1){
						
						account.editAccount(newName, newLevel);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
					System.out.println("Successfully edited Account.");
				}

				//processing for remove user
				if(command.equalsIgnoreCase("removeuser")){
					String newName = getInput("Enter Student Name");
					
					//only allow admins to remove users
					if(userLevel == 1){
					
						account.removeAccount(newName);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
					System.out.println("Successfully removed account.");
				}
				if(command.equalsIgnoreCase("createstudymaterial")){
					String newName = getInput("Enter Study Material Name");
					
					//only allow admins to remove users
	/*				if(userLevel == 1){
					
						account.removeAccount(newName);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
		*/			System.out.println("Successfully created study material.");
				}
				if(command.equalsIgnoreCase("editstudymaterial")){
					String newName = getInput("Enter Study Material Name");
					int studymaterialID  = Integer.parseInt(getInput("Enter study material id"));
					//only allow admins to remove users
	/*				if(userLevel == 1){
					
						account.removeAccount(newName);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
		*/			System.out.println("Successfully edited study material.");
				}
				if(command.equalsIgnoreCase("getstudentsfromclass")){
					int classID  = Integer.parseInt(getInput("Enter class id"));
					//only allow admins to remove users
	/*				if(userLevel == 1){
					
						account.removeAccount(newName);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
		*/			System.out.println("Successfully got students from class.");
				}
				if(command.equalsIgnoreCase("getstudymaterialfromclass")){
					int classID  = Integer.parseInt(getInput("Enter class id"));
					//only allow admins to remove users
	/*				if(userLevel == 1){
					
						account.removeAccount(newName);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
		*/			System.out.println("Successfully got study material from class.");
				}
				if(command.equalsIgnoreCase("editclass")){
					String newName = getInput("Enter Class Name");
					int classID  = Integer.parseInt(getInput("Enter class id"));
					//only allow admins to remove users
	/*				if(userLevel == 1){
					
						account.removeAccount(newName);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
		*/			System.out.println("Successfully edited class.");
				}
				if(command.equalsIgnoreCase("addstudymaterialtoclass")){
					int studymaterialID  = Integer.parseInt(getInput("Enter study material id"));
					int classID  = Integer.parseInt(getInput("Enter class id"));
					//only allow admins to remove users
	/*				if(userLevel == 1){
					
						account.removeAccount(newName);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
		*/			System.out.println("Successfully adds study material to class.");
				}
				if(command.equalsIgnoreCase("removestudymaterialfromclass")){
					int studymaterialID  = Integer.parseInt(getInput("Enter study material id"));
					int classID  = Integer.parseInt(getInput("Enter class id"));
					//only allow admins to remove users
	/*				if(userLevel == 1){
					
						account.removeAccount(newName);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
		*/			System.out.println("Successfully removes study material from class.");
				}
				if(command.equalsIgnoreCase("deletestudymaterial")){
					int studymaterialID  = Integer.parseInt(getInput("Enter study material id"));
					//only allow admins to remove users
	/*				if(userLevel == 1){
					
						account.removeAccount(newName);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
		*/			System.out.println("Successfully deleted study material.");
				}
				if(command.equalsIgnoreCase("createclass")){
					String newName  =getInput("Enter Class Name");
					//only allow admins to remove users
	/*				if(userLevel == 1){
					
						account.removeAccount(newName);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
		*/			System.out.println("Successfully created class.");
				}
				if(command.equalsIgnoreCase("removestudentfromclass")){
					int studentlID  = Integer.parseInt(getInput("Enter student id"));
					int classID  = Integer.parseInt(getInput("Enter class id"));
					//only allow admins to remove users
	/*				if(userLevel == 1){
					
						account.removeAccount(newName);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
		*/			System.out.println("Successfully removed student from class.");
				}
				if(command.equalsIgnoreCase("addstudenttoclass")){
					int studentID  = Integer.parseInt(getInput("Enter student id"));
					int classID  = Integer.parseInt(getInput("Enter class id"));
					//only allow admins to remove users
	/*				if(userLevel == 1){
					
						account.removeAccount(newName);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
		*/			System.out.println("Successfully added student to class.");
				}
				if(command.equalsIgnoreCase("deleteclass")){
					int classID  = Integer.parseInt(getInput("Enter class id"));
					//only allow admins to remove users
	/*				if(userLevel == 1){
					
						account.removeAccount(newName);
						
					}
					else{
						System.out.println("Cannot execute that command.");
					}
		*/			System.out.println("Successfully deleted class.");
				}
				
				
			}

		}

	}

	private static String getInput(String prompt){
		System.out.println(prompt);
		System.out.print(":");
		return in.nextLine();
	}
	
	
	private static void showOptions(int userLevel){
		if(userLevel == 0){
			return;
		}
		if(userLevel == 1){
			System.out.println("Allowable Commands:");
			System.out.println("AddUser");
			System.out.println("RemoveUser");
			System.out.println("EditUser");
			return;
		}
		if(userLevel == 2){
			System.out.println("Allowable Commands:");
			System.out.println("AddUser");
			return;
		}
		if(userLevel == 3){
			System.out.println("Allowable Commands:");
			System.out.println("None");
			return;
		}
		
	}
}
